<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>订单转为出库单</title>
  </head>
  <body>
    <script type="text/javascript">
      Ext.onReady(function(){
        var saleOrderId = new Ext.form.Hidden({
          name: 'sale_order_id',
          value: '<%=params[:sale_order_id]%>'
        });
        
        //所有仓库
        var warehouseTemplate = new Ext.XTemplate('<tpl for="."><div class="search-item"><div style="float:left; width:120px">{name}</div><div>{number}</div></div></tpl>');
        var warehouseStore = new Ext.data.Store({
          proxy: new Ext.data.HttpProxy({
            url: "/warehouse/getAllWarehouse?for_cbb=true"
          }),
          reader: new Ext.data.JsonReader({
            root: 'root'
          }, [{
              name: 'id'
            },{
              name: 'number'
            }, {
              name: 'name'
            }])
        });

        var fromWarehouse = new Ext.form.ComboBox({
          store: warehouseStore,
          fieldLabel: '出货仓库',
          allowBlank: false,
          blankText: "出货仓库必须选择",
          emptyText: '请选择出货仓库...',
          valueField: 'id',
          displayField: 'name',
          hiddenName: 'warehouse_id',
          //typeAhead: false,
          loadingText: '搜索中...',
          anchor: '90%',
          //pageSize: 10,
          //hideTrigger: false,
          tpl: warehouseTemplate,
          minChars: 0,
          itemSelector: 'div.search-item',
          triggerAction:'all',
          selectOnFocus:true
        });
        
        //提交按钮
        var deliveryOrderButton = new Ext.Button({
          text: '提交',
          iconCls: 'icon-save',
          handler: function(){
            deliveryOrderButton.setDisabled(true);
            if (saleOrderDeliveryFormPanel.form.isValid()) {
              saleOrderDeliveryFormPanel.form.submit({
                success: function(result, resp){
                  if (resp.result.info.indexOf("成功") >= 0) {
                    saleOrderDeliveryWin.destroy();
                  } else {
                    Ext.MessageBox.show({
                      title: '消息',
                      msg: resp.result.info,
                      buttons: Ext.MessageBox.OK,
                      icon: Ext.MessageBox.WARNING
                    });                    
                  }
                  deliveryOrderButton.enable();
                },
                failure: function(result, request){
                  deliveryOrderButton.enable();
                  Ext.MessageBox.show({
                    title: '消息',
                    msg: "通讯失败，请从新操作",
                    buttons: Ext.MessageBox.OK,
                    icon: Ext.MessageBox.WARNING
                  });
                }
              });
            }
            else {
              deliveryOrderButton.enable();
              
            }
          }
        })
        
        var saleOrderDeliveryFormPanel = new Ext.form.FormPanel({
          labelWidth: 75,
          width: '290',
          labelAlign: 'right',
          frame : true,
          url: '/delivery_order/transformSaleIntoDelivery',
          method: 'GET',
          items: [saleOrderId,fromWarehouse],
          buttons: [deliveryOrderButton,{
              text: '关闭',
              iconCls: 'exit',
              handler: function(){
                saleOrderDeliveryWin.destroy();
              }
            }]
        });
        saleOrderDeliveryFormPanel.render('delivery_sale_order_form');
      })
    </script>
    <div id="delivery_sale_order_form"></div>
  </body>
</html>
